home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / mail / pine3.96.tar.gz / pine3.96.tar / pine3.96 / imap / ANSI / c-client / env_vms.c < prev    next >
C/C++ Source or Header  |  1994-09-14  |  7KB  |  226 lines

  1. /*
  2.  * Program:    VMS environment routines
  3.  *
  4.  * Author:    Yehavi Bourvine, The Hebrew University of Jerusalem
  5.  *        Internet: Yehavi@VMS.huji.ac.il
  6.  *
  7.  * Date:    2 August 1994
  8.  * Last Edited:    14 September 1994
  9.  *
  10.  * Copyright 1994 by the University of Washington
  11.  *
  12.  *  Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose and without fee is hereby granted, provided
  14.  * that the above copyright notice appears in all copies and that both the
  15.  * above copyright notice and this permission notice appear in supporting
  16.  * documentation, and that the name of the University of Washington not be
  17.  * used in advertising or publicity pertaining to distribution of the software
  18.  * without specific, written prior permission.    This software is made available
  19.  * "as is", and
  20.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  21.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  22.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  23.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  24.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  25.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  26.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  27.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  28.  *
  29.  */
  30.  
  31.  
  32. static char *myUserName = NIL;    /* user name */
  33. static char *myLocalHost = NIL;    /* local host name */
  34. static char *myHomeDir = NIL;    /* home directory name */
  35. static char *myNewsrc = NIL;    /* newsrc file name */
  36. static MAILSTREAM *defaultProto = NIL;
  37. static char *userFlags[NUSERFLAGS] = {NIL};
  38.  
  39. /* Environment manipulate parameters
  40.  * Accepts: function code
  41.  *        function-dependent value
  42.  * Returns: function-dependent return value
  43.  */
  44.  
  45. void *env_parameters (long function,void *value)
  46. {
  47.   switch ((int) function) {
  48.   case SET_USERNAME:
  49.     myUserName = cpystr ((char *) value);
  50.     break;
  51.   case GET_USERNAME:
  52.     value = (void *) myUserName;
  53.     break;
  54.   case SET_HOMEDIR:
  55.     myHomeDir = cpystr ((char *) value);
  56.     break;
  57.   case GET_HOMEDIR:
  58.     value = (void *) myHomeDir;
  59.     break;
  60.   case SET_LOCALHOST:
  61.     myLocalHost = cpystr ((char *) value);
  62.     break;
  63.   case GET_LOCALHOST:
  64.     value = (void *) myLocalHost;
  65.     break;
  66.   case SET_NEWSRC:
  67.     if (myNewsrc) fs_give ((void **) &myNewsrc);
  68.     myNewsrc = cpystr ((char *) value);
  69.     break;
  70.   case GET_NEWSRC:
  71.     if (!myNewsrc) {        /* set news file name if not defined */
  72.       char tmp[MAILTMPLEN];
  73.       sprintf (tmp,"%s:.newsrc",myhomedir ());
  74.       myNewsrc = cpystr (tmp);
  75.     }
  76.     value = (void *) myNewsrc;
  77.     break;
  78.   default:
  79.     value = NIL;        /* error case */
  80.     break;
  81.   }
  82.   return value;
  83. }
  84.  
  85. /* Write current time in RFC 822 format
  86.  * Accepts: destination string
  87.  */
  88.  
  89. void rfc822_date (char *date)
  90. {
  91.   long clock;
  92.   struct tm *t;
  93.   struct timeval tv;
  94.   time (&clock);
  95.   t = localtime (&clock);    /* convert to individual items */
  96.                 /* note: need code to do timezone right */
  97.   sprintf (date,"%s, %d %s %d %02d:%02d:%02d +0000",
  98.        days[t->tm_wday],t->tm_mday,months[t->tm_mon],t->tm_year+1900,
  99.        t->tm_hour,t->tm_min,t->tm_sec);
  100. }
  101.  
  102.  
  103. /* Write current time in internal format
  104.  * Accepts: destination string
  105.  */
  106.  
  107. void internal_date (char *date)
  108. {
  109.   long clock;
  110.   struct tm *t;
  111.   struct timeval tv;
  112.   time (&clock);
  113.   t = localtime (&clock);    /* convert to individual items */
  114.                 /* note: need code to do timezone right */
  115.   sprintf (date,"%2d-%s-%d %02d:%02d:%02d +0000",
  116.        t->tm_mday,months[t->tm_mon],t->tm_year+1900,
  117.        t->tm_hour,t->tm_min,t->tm_sec);
  118. }
  119.  
  120. /* Return my user name
  121.  * Returns: my user name
  122.  */
  123.  
  124. char *myusername ()
  125. {
  126.   extern MAILSTREAM STDPROTO;
  127.   struct stat sbuf;
  128.   char tmp[MAILTMPLEN];
  129.  
  130.   if (!myUserName) {        /* get user name if don't have it yet */
  131.     myUserName = cpystr (cuserid (NULL));
  132.     myHomeDir = cpystr ("SYS$LOGIN");
  133.                 /* do configuration files */
  134.     dorc (strcat (strcpy (tmp,myhomedir ()),":.imaprc"));
  135.     dorc (strcat (strcpy (tmp,myhomedir ()),":.mminit"));
  136.     dorc ("UTIL$:imapd.conf");
  137.     if (!defaultProto) defaultProto = &STDPROTO;
  138.   }
  139.   return myUserName;
  140. }
  141.  
  142.  
  143. /* Return my home directory name
  144.  * Returns: my home directory name
  145.  */
  146.  
  147. char *myhomedir ()
  148. {
  149.   if (!myHomeDir) myusername ();/* initialize if first time */
  150.   return myHomeDir;
  151. }
  152.  
  153.  
  154. /* Determine default prototype stream to user
  155.  * Returns: default prototype stream
  156.  */
  157.  
  158. MAILSTREAM *default_proto ()
  159. {
  160.   myusername ();        /* make sure initialized */
  161.   return defaultProto;        /* return default driver's prototype */
  162. }
  163.  
  164. /* Set up user flags for stream
  165.  * Accepts: MAIL stream
  166.  * Returns: MAIL stream with user flags set up
  167.  */
  168.  
  169. MAILSTREAM *user_flags (MAILSTREAM *stream)
  170. {
  171.   int i;
  172.   myusername ();        /* make sure initialized */
  173.   for (i = 0; i < NUSERFLAGS; ++i) stream->user_flags[i] = userFlags[i];
  174.   return stream;
  175. }
  176.  
  177. /* Process rc file
  178.  * Accepts: file name
  179.  */
  180.  
  181. void dorc (char *file)
  182. {
  183.   int i;
  184.   char *s,*t,*k,tmp[MAILTMPLEN],tmpx[MAILTMPLEN];
  185.   extern DRIVER *maildrivers;
  186.   extern MAILSTREAM STDPROTO;
  187.   DRIVER *d;
  188.   FILE *f = fopen (file,"r");
  189.   if (!f) return;        /* punt if no file */
  190.   while ((s = fgets (tmp,MAILTMPLEN,f)) && (t = strchr (s,'\n'))) {
  191.     *t++ = '\0';        /* tie off line, find second space */
  192.     if ((k = strchr (s,' ')) && (k = strchr (++k,' '))) {
  193.       *k++ = '\0';        /* tie off two words*/
  194.       lcase (s);        /* make case-independent */
  195.       if (!(defaultProto || strcmp (s,"set empty-folder-format"))) {
  196.     if (!strcmp (lcase (k),"same-as-inbox"))
  197.       defaultProto = ((d = mail_valid (NIL,"INBOX",NIL)) &&
  198.               strcmp (d->name,"dummy")) ?
  199.                 ((*d->open) (NIL)) : &STDPROTO;
  200.     else if (!strcmp (k,"system-standard")) defaultProto = &STDPROTO;
  201.     else {            /* see if a driver name */
  202.       for (d = maildrivers; d && strcmp (d->name,k); d = d->next);
  203.       if (d) defaultProto = (*d->open) (NIL);
  204.       else {        /* duh... */
  205.         sprintf (tmpx,"Unknown empty folder format in %s: %s",file,k);
  206.         mm_log (tmpx,WARN);
  207.       }
  208.     }
  209.       }
  210.       else if (!(userFlags[0] || strcmp (s,"set keywords"))) {
  211.     k = strtok (k,", ");    /* yes, get first keyword */
  212.                 /* copy keyword list */
  213.     for (i = 0; k && i < NUSERFLAGS; ++i) {
  214.       userFlags[i] = cpystr (k);
  215.       k = strtok (NIL,", ");
  216.     }
  217.       }
  218.       else if (!strcmp (s,"set from-widget"))
  219.     mail_parameters (NIL,SET_FROMWIDGET,strcmp (lcase (k),"header-only") ?
  220.              (void *) T : NIL);
  221.     }
  222.     s = t;            /* try next line */
  223.   }
  224.   fclose (f);            /* flush the file */
  225. }
  226.